CREATE TABLE [dbo].[DnnProduct_FolderPermission]
(
[FolderPermissionID] [int] NOT NULL IDENTITY(1, 1),
[FolderID] [int] NOT NULL,
[PermissionID] [int] NOT NULL,
[AllowAccess] [bit] NOT NULL,
[RoleID] [int] NULL,
[UserID] [int] NULL,
[CreatedByUserID] [int] NULL,
[CreatedOnDate] [datetime] NULL,
[LastModifiedByUserID] [int] NULL,
[LastModifiedOnDate] [datetime] NULL
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[DnnProduct_FolderPermission] ADD CONSTRAINT [PK_DnnProduct_FolderPermission] PRIMARY KEY CLUSTERED  ([FolderPermissionID]) WITH (FILLFACTOR=85) ON [PRIMARY]
GO
ALTER TABLE [dbo].[DnnProduct_FolderPermission] ADD CONSTRAINT [IX_DnnProduct_FolderPermission] UNIQUE NONCLUSTERED  ([FolderID], [PermissionID], [RoleID], [UserID]) WITH (FILLFACTOR=85) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_DnnProduct_FolderPermission_Modules] ON [dbo].[DnnProduct_FolderPermission] ([FolderID]) WITH (FILLFACTOR=85) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_DnnProduct_FolderPermission_Permission] ON [dbo].[DnnProduct_FolderPermission] ([PermissionID]) WITH (FILLFACTOR=85) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_DnnProduct_FolderPermission_Roles] ON [dbo].[DnnProduct_FolderPermission] ([RoleID]) WITH (FILLFACTOR=85) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_DnnProduct_FolderPermission_Users] ON [dbo].[DnnProduct_FolderPermission] ([UserID]) WITH (FILLFACTOR=85) ON [PRIMARY]
GO
ALTER TABLE [dbo].[DnnProduct_FolderPermission] ADD CONSTRAINT [FK_DnnProduct_FolderPermission_DnnProduct_Folders] FOREIGN KEY ([FolderID]) REFERENCES [dbo].[DnnProduct_Folders] ([FolderID]) ON DELETE CASCADE
GO
ALTER TABLE [dbo].[DnnProduct_FolderPermission] WITH NOCHECK ADD CONSTRAINT [FK_DnnProduct_FolderPermission_DnnProduct_Permission] FOREIGN KEY ([PermissionID]) REFERENCES [dbo].[DnnProduct_Permission] ([PermissionID]) ON DELETE CASCADE
GO
ALTER TABLE [dbo].[DnnProduct_FolderPermission] ADD CONSTRAINT [FK_DnnProduct_FolderPermissionDnnProduct_Users] FOREIGN KEY ([UserID]) REFERENCES [dbo].[DnnProduct_Users] ([UserID]) ON DELETE CASCADE
GO
